home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15887 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: trib.apple.com!usenet
  2. From: Amir <Amir@bayarea.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Experiences calling C++ from C?
  5. Date: Mon, 08 Apr 1996 10:36:55 -0700
  6. Organization: Apple Computer, Inc., Cupertino, California
  7. Message-ID: <31694EB7.6C0C@bayarea.net>
  8. References: <SCHOLZ.96Apr7012849@otto.inf.fu-berlin.de>
  9. NNTP-Posting-Host: a17-128-200-53.apple.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (Macintosh; I; PPC)
  14.  
  15. > Hello,
  16. >     I would greatly appreciate any help with calling C++ functions
  17. > from C!
  18. >     I have read the FAQ, I know that one must declare the C++
  19. > functions with "extern C++" and I'm passing nothing but void pointers
  20. > (no structs), but still my program crashes in the first C++ function:
  21. > The gdb stack shows a number of invocations of some unknown-to-me
  22. > function _end (), followed by a segmentation fault in a constructor
  23. > function I never call.
  24. >    Any help will be most welcome!
  25. > Enno
  26.  
  27. Hello
  28.  
  29. I'll try to guess what is the problem. I dealt with that
  30. a couple of years ago, so if I don't remember correctly, I hope
  31. someone will give the right answer.
  32.  
  33. if you have a Global variables in the C++ module, Its
  34. constructors and destructors are called from a special
  35. functions that are created by the C++ compiler for each
  36. module that has Global variables.
  37.  
  38. Now, if I remember correctly, if your main is in C, these function
  39. that should be called before the main are never called.
  40. so you have three solutions:
  41.  
  42. 1. Make the main in the C++ part (prob you need to link with a C++
  43.    linker)
  44. 2. Don't have any global instances.
  45. 3. If you must have the main in C, and you must have global
  46.    variables, you can find the name of all the special functions 
  47.    and call them yourself as the VERY FIRST lines in your C main
  48.    function (this is what I had to do)
  49.  
  50.  
  51. Amir
  52.  
  53. -- 
  54.  
  55.                     \\||||//
  56.                     \ o  o /
  57. ______________.ooO__(  ()  )__Ooo._______________________________
  58.  
  59.    Amir Deutel                  http://www.bayarea.net/~amir/
  60.  
  61.                  .oo0O   O0oo.  Work: Amir.D@AppleLink.Apple.com
  62.                  (   )   (   )  Home: Amir@bayarea.net
  63. __________________\ (_____) /____________________________________
  64.                    \_)   (_/
  65.